/*
 * Adam Blackwell
 * ada2358@ccs.neu.edu
 */

/***********************************************************************
 * Artifact class
 * 
 * Implements the root of the artifact hierarchy
 *
 * Signature:
 *  public void install ();
 *  public void destroy ();
 *  public Coord position ();
 *  public String name ();
 *  public void report (String message);
 *  public void changePosition (Coord target);
 *  public boolean isOrbitable ();
 *  public void takeDamage (int damage);
 *  public abstract char display ();
 *  public abstract String toString ();
 ***********************************************************************/

/**
 * Artifact:
 * @author Adam
 *
 */
public abstract class Artifact {
  private String name;
  private Coord  position;
  
  /**
   * Protected Constructor:
   * @param n
   * @param p
   */
  protected Artifact(String n, Coord p) {
    this.name = Util.noSpaces(n);
    this.position = p;
  }
  
  /**
   * Install:
   */
  public void install() {
    Coord size = SpaceGame.map().size();
    SpaceGame.updateMap(Map.merge(Map.artifact(size.xPos(), size.yPos(), this),
                                  SpaceGame.map()));
  }
  
  /**
   * Destroy:
   */
  public void destroy() {
    SpaceGame.updateMap(SpaceGame.map().removeArtifact(this));
  }
  
  /**
   * Position:
   * @return
   */
  public Coord position() {
    return this.position;
  }
  
  /**
   * Name:
   * @return
   */
  public String name() {
    return this.name;
  }
  
  /**
   * Report:
   * @param s
   */
  public void report(String s) {
    if (SpaceGame.isGodMode())
      System.out.println(this.name() + " reports -- " + s);
  }
  
  /**
   * ChangePosition:
   * @param c
   */
  public void changePosition(Coord c) {
    if (!c.within(Coord.create(0, 0), SpaceGame.map().size().move(-1, -1)))
      throw new IllegalArgumentException("Artifact.changePosition()");
    position = c;
  }
  
  /**
   * IsOrbitable:
   * @return
   */
  public boolean isOrbitable() {
    return false;
  }
  
  /**
   * Take Damage:
   * @param d
   */
  public void takeDamage(int d) {
    report("no damage");
  }
  
  /**
   * Display:
   * @return
   */
  public abstract char display();
  
  /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
  public abstract String toString();
}


